
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="__STATIC__/component/pear/css/pear.css" />
</head>
<body>
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        中文名称
                    </label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" name="cname" lay-verify="required" value="{$desc??''}" type="text"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生成菜单</label>
                    <div class="layui-input-block">
                        <input type="radio" name="menu-type" value="1" title="生成" checked lay-filter="type">
                        <input type="radio" name="menu-type" value="2" title="不生成" lay-filter="type">
                    </div>
                    <div class="layui-form-item" id="menu">
                        <div class="layui-form-item">
                            <label for="" class="layui-form-label">父级</label>
                            <div class="layui-input-block">
                                <select name="menu-pid" lay-verify="requried">
                                    {foreach $permissions as $k1=>$p1}
                                        <option value="{$p1.id}">{$p1.title}</option>
                                        {if isset($p1['children']) && !empty($p1['children']) }
                                            {foreach $p1['children'] as $k2=>$p2}
                                                <option value="{$p2.id}" >&nbsp;&nbsp;&nbsp;┗━━{$p2.title}</option>
                                            {/foreach}
                                        {/if}
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label for="" class="layui-form-label">图标</label>
                            <div class="layui-input-block">
                                <div class="layui-input-inline" style="width: unset">
                                    <input type="text" id="iconPicker2" name="menu-icon" value="" lay-filter="iconPicker2" class="hide">
                                </div>
                                <div class="layui-input-inline" style="width: unset">
                                    <span class="pear-btn" id="clear">清空</span>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label for="" class="layui-form-label">排序</label>
                            <div class="layui-input-block">
                                <input type="number" name="menu-sort" value="10" lay-verify="required" placeholder="排序权重" class="layui-input" >
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body">
                        如无特殊需求，下列选项可以忽略
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            搜索字段
                        </label>
                        <div class="layui-input-block">
                            {volist name="$info" id="v"}
                                {if condition="!in_array($v['COLUMN_NAME'], ['delete_time'])"}
                                    <input type="checkbox" lay-skin="primary" name="sql-search[]" value="{$v.COLUMN_NAME}###{$v.COLUMN_COMMENT}###{$v.IS_NULLABLE}" title="{$v.COLUMN_NAME}" >
                                {/if}
                            {/volist}
                        </div>
                    </div>
                    <div class="layui-card-body">
                        下列选项同一字段只可设置一种
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            编辑器字段
                        </label>
                        <div class="layui-input-block">
                            {volist name="$info" id="v"}
                            {if condition="!in_array($v['COLUMN_NAME'], ['create_time', 'update_time','delete_time'])"}
                            <input type="checkbox" lay-skin="primary" name="sql-edit[]" value="{$v.COLUMN_NAME}###{$v.COLUMN_COMMENT}###{$v.IS_NULLABLE}" title="{$v.COLUMN_NAME}" >
                            {/if}
                            {/volist}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            图片字段
                        </label>
                        <div class="layui-input-block">
                            {volist name="$info" id="v"}
                            {if condition="!in_array($v['COLUMN_NAME'], ['create_time', 'update_time','delete_time'])"}
                            <input type="checkbox" lay-skin="primary" name="sql-photo[]" value="{$v.COLUMN_NAME}###{$v.COLUMN_COMMENT}###{$v.IS_NULLABLE}" title="{$v.COLUMN_NAME}" >
                            {/if}
                            {/volist}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js"></script>
<script>
layui.use(['form','jquery','iconPicker'],function(){
    let form = layui.form;
    let $ = layui.jquery;
    let iconPicker= layui.iconPicker;
    form.on('submit(save)', function(data){
        $.ajax({
            data:data.field,
            dataType:'json',
            type:'post',
            success:function(res){
                if (res.code==200) {
                    layer.msg(res.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.location.reload();
                    });
                }else{
                    layer.msg(res.msg,{icon:2,time:1000});
                }
            }
        })
        return false;
    });

    iconPicker.render({
        elem: '#iconPicker2',
        type: 'fontClass',
        search: true,
        // 是否开启分页
        page: true,
        limit: 12,
        click: function (data) {
        },
        success: function(d) {
        }
    });

    $('#clear').click(function() {
        $('#iconPicker2').attr("value","");
        $('.layui-iconpicker-icon').children("i").attr("class","layui-icon layui-icon-circle-dot");
    });

    form.on('radio(type)', function(data){
        if(data.value==1){
            $("#menu").show();
        }else{
            $("#menu").hide();
        }
    }); 

})
</script>
</body>
</html>